import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Scanner;

/**
 * 
 */

/**
 * @author Bryan
 *
 */
public class LogInOut {
	private static Collection<Employee> employees = new ArrayList<Employee>();
	
	int count=0;
	public String logIN(String ID){
		String f = " ";
		
		if(count==0)
		{
			load("emps.txt");
		}
		count++;
		for(Employee e: employees){
			if(e.geteNumber().equals(ID)){
				f = e.geteJob();
				return f;
			}
		}
		return "error";
	}
	
	//*************************************************************************
		/**
		 * Using the scanner function and delimiter function a .txt file is read into the program.
		 * The first object read in is a string, followed by a double. The delimiter identifies commas
		 * and spaces as separators between objects.
		 */
	public static void load(String fileName){

			try {
				 File file = new File(fileName);
		         Scanner scanner = new Scanner(file);
		         scanner.useDelimiter(System.getProperty("line.separator")); 
		         while(scanner.hasNext())
		         {
		        	Scanner lineScanner = new Scanner(scanner.next());
		     	    lineScanner.useDelimiter("\\s*,\\s*");
		     	    String jTYPE = lineScanner.next();
		     	    String eName = lineScanner.next();
		     	    String eID = lineScanner.next();
		     	    Employee m = new Employee(jTYPE, eName, eID);
		     	    employees.add(m);
		         }
		         scanner.close();
		     } catch (FileNotFoundException e) 
		     	{
		    	 	e.printStackTrace();
		     	}
		} //End Load
	//*************************************************************************
	
		public static String printEmployees(int i){
			String output="";
			
			for(Employee z: employees){
				
				output= output.concat("Name: " + z.getName()
				+"\tEmployee ID: "+z.geteNumber()+"\tJob: "+z.geteJob()+"\n");
				}
		//	System.out.println(output);
				return output;

		}
}
